package com.ruoyi.sale.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.base.domain.vo.LotteryVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sale.domain.SaleLotterySix;
import com.ruoyi.sale.service.ISaleLotterySixService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 组六彩票售卖Controller
 *
 * @author szm
 * @date 2025-09-25
 */
@Api(tags = "组六彩票售卖接口")
@RestController
@RequestMapping("/sale/SaleLotterySix")
public class SaleLotterySixController extends BaseController {
    @Autowired
    private ISaleLotterySixService saleLotterySixService;

    /**
     * 查询组六彩票售卖列表
     */
    @ApiOperation("查询组六彩票售卖列表")
    @GetMapping("/list")
    public TableDataInfo list(SaleLotterySix entity, HttpServletRequest req) {
        startPage();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.setEntity(entity);
        //wrapper.orderByDesc("create_time");
        wrapper.orderByDesc("multiple");
        List<SaleLotterySix> list = saleLotterySixService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出组六彩票售卖列表
     */
    @ApiOperation("导出组六彩票售卖列表")
    @Log(title = "组六彩票售卖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleLotterySix entity) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.setEntity(entity);
        List<SaleLotterySix> list = saleLotterySixService.list(wrapper);
        ExcelUtil<SaleLotterySix> util = new ExcelUtil<SaleLotterySix>(SaleLotterySix. class);
        util.exportExcel(response, list, "组六彩票售卖数据");
    }

    /**
     * 获取组六彩票售卖详细信息
     */
    @ApiOperation("获取组六彩票售卖详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getById(@PathVariable("id") String id) {
        return success(saleLotterySixService.getById(id));
    }

    /**
     * 新增组六彩票售卖
     */
    @ApiOperation("新增组六彩票售卖")
    @Log(title = "组六彩票售卖", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SaleLotterySix entity) {
        return toAjax(saleLotterySixService.saveOrUpdate(entity));
    }

    /**
     * 修改组六彩票售卖
     */
    @ApiOperation("修改组六彩票售卖")
    @Log(title = "组六彩票售卖", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SaleLotterySix entity) {
        return toAjax(saleLotterySixService.updateById(entity));
    }

    /**
     * 删除组六彩票售卖
     */
    @ApiOperation("删除组六彩票售卖")
    @Log(title = "组六彩票售卖", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(saleLotterySixService.removeById(ids));
    }

    @ApiOperation("获取彩票图片数据")
    @GetMapping("/getImageList")
    public AjaxResult getImageList(@RequestParam("id") String id) {
        SaleLotterySix entity = saleLotterySixService.getById(id);
        if (entity != null){
            List<LotteryVo> b = saleLotterySixService.getImageList(entity.getBaseId());
            return AjaxResult.success(b);
        }
        return AjaxResult.success();
    }
}
